﻿Imports System.Windows.Forms
Imports System.Drawing

'用于显示平行于坐标轴的矩形
<Serializable()> Public Class ParaRectangleTool
    Inherits BaseTool


    Dim dp2 As New Point
    Dim dp3 As New Point
    Dim dp4 As New Point

    Dim dp2_old As New Point
    Dim dp3_old As New Point
    Dim dp4_old As New Point

    Dim pt As New Point
    Dim length As Integer

    Public Overrides Sub mouseDblClick(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Public Overrides Sub mouseDown(ByVal sender As Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent)
        If e.button = 1 Then



            If Me.OperShapeProperty Is Nothing Then '第一次绘制



                Me.OperShapeProperty = ShapeFactory.getNewLineShape()


                Me.OperShapeProperty.P1Property = Me.DownPointProperty
                Me.OperShapeProperty.plist.Add(Me.DownPointProperty)

                dp2_old = Me.DownPointProperty
                dp4_old = Me.DownPointProperty




            Else
                Me.OperShapeProperty.plist.Add(dp2)

                Me.OperShapeProperty.plist.Add(dp3)

                Me.OperShapeProperty.plist.Add(dp4)




                InvokeEndDrawing()
                Me.OperShapeProperty = Nothing




            End If

        End If
    End Sub

    Public Overrides Sub mouseDrag(ByVal sender As Object, ByVal e As AxMapWinGIS._DMapEvents_MouseMoveEvent)

    End Sub

    Public Overrides Sub mouseMove(ByVal sender As Object, ByVal e As AxMapWinGIS._DMapEvents_MouseMoveEvent)
        If Me.OperShapeProperty.plist.Count = 1 Then


            pt.X = e.x
            pt.Y = e.y

            dp3.X = e.x
            dp3.Y = e.y


            dp2.X = dp3.X
            dp2.Y = Me.DownPointProperty.Y


            dp4.X = Me.DownPointProperty.X
            dp4.Y = dp3.Y


            'If Math.Abs(pt.X - Me.DownPointProperty.X) > Math.Abs(pt.Y - Me.DownPointProperty.Y) Then
            '    length = Math.Abs(pt.Y - Me.DownPointProperty.Y)

            'Else
            '    length = Math.Abs(pt.X - Me.DownPointProperty.X)

            'End If

            'If Me.DownPointProperty.X > pt.X Then

            '    dp2.X = Me.DownPointProperty.X - length
            '    dp2.Y = Me.DownPointProperty.Y
            'Else

            '    dp2.X = Me.DownPointProperty.X + length
            '    dp2.Y = Me.DownPointProperty.Y
            'End If


            'If Me.DownPointProperty.Y > pt.Y Then

            '    dp4.X = Me.DownPointProperty.X
            '    dp4.Y = Me.DownPointProperty.Y - length
            'Else

            '    dp4.X = Me.DownPointProperty.X
            '    dp4.Y = Me.DownPointProperty.Y + length

            'End If

            'dp3.X = dp2.X
            'dp3.Y = dp4.Y


            '下面进入精彩绝伦，绕死你不偿命的正反线绘制阶段

            ControlPaint.DrawReversibleLine(getScreen(Me.OperShapeProperty.plist.Item(0)), getScreen(dp2_old), lColor)

            ControlPaint.DrawReversibleLine(getScreen(Me.OperShapeProperty.plist.Item(0)), getScreen(dp2), lColor)

            ControlPaint.DrawReversibleLine(getScreen(Me.OperShapeProperty.plist.Item(0)), getScreen(dp4_old), lColor)

            ControlPaint.DrawReversibleLine(getScreen(Me.OperShapeProperty.plist.Item(0)), getScreen(dp4), lColor)



            ControlPaint.DrawReversibleLine(getScreen(dp3_old), getScreen(dp2_old), lColor)

            ControlPaint.DrawReversibleLine(getScreen(dp3), getScreen(dp2), lColor)

            ControlPaint.DrawReversibleLine(getScreen(dp3_old), getScreen(dp4_old), lColor)

            ControlPaint.DrawReversibleLine(getScreen(dp3), getScreen(dp4), lColor)





            '刷新旧有坐标啦

            dp2_old = dp2
            dp3_old = dp3
            dp4_old = dp4

        End If

    End Sub

    Public Overrides Sub mouseUp(ByVal sender As Object, ByVal e As AxMapWinGIS._DMapEvents_MouseUpEvent)

    End Sub

    Public Overrides Sub setself()

    End Sub

    Public Overrides Sub unSet()

    End Sub

End Class
